﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using NHibernate;
using ZLCMS.Business;
using DotNet.Common.NHibernateUtil;

namespace ZLCMS.Web.SystemManage.Basics.RightConfig.User
{
    public partial class UserDelete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FrameHelper framePage = new FrameHelper(this);
            string ids = Request["ids"];
            if (!string.IsNullOrEmpty(ids))
            {
                string[] idStrs = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                //IList<int> idList = new List<int>();
                //foreach (string acc in idStrs)
                //{
                //    if (!string.IsNullOrEmpty(acc))
                //    {
                //        idList.Add(Int32.Parse(acc));
                //    }
                //}
                using (ISession session = SessionFactoryHelper.CreateSession())
                {
                    //删除
                    if (Request["del"] == "1")
                    {
                        session.CreateSQLQuery("delete from sys_user_info  where user_account in (:ids)")
                            .SetParameterList("ids", idStrs.ToArray())
                            .ExecuteUpdate();
                        session.CreateSQLQuery("delete from shop_agent_info  where agent_account in (:ids)")
                            .SetParameterList("ids", idStrs.ToArray())
                            .ExecuteUpdate();
                        session.CreateSQLQuery("delete from ur_user_role  where user_code in (:ids)")
                            .SetParameterList("ids", idStrs.ToArray())
                            .ExecuteUpdate();
                    }
                    else
                    {
                        session.CreateSQLQuery("update sys_user_info set status=:stat where user_account in (:ids)")
                            .SetParameter("stat", Request["stat"])
                            .SetParameterList("ids", idStrs.ToArray())
                            .ExecuteUpdate();
                    }
                    session.Flush();
                    framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = framePage.NavTabId });
                }
            }
            else
            {
                framePage.Alert(new ReturnCode() { statusCode = 300, message = "参数错误" });
            }
        }
    }
}
